<template>
  <view class="container">
    <!-- 余额 -->
    <image src="../../static/img/walltbgc.png" mode="aspectFill" class="bgc"></image>
    <view class="money">
      <view>
        <view>余额(元)</view>
        <view style="margin-top: 18rpx; font-size: 40rpx; font-family: PingFang SC, PingFang SC; font-weight: bold">{{ data.money }}</view>
      </view>
      <view class="tixian" @click="tixian">提现</view>
    </view>
    <!-- navbar切换 -->
    <view class="navbarbox">
      <view :class="{ common: index == 1 }" @click="changenav1">收支明细</view>
      <view :class="{ common: index == 2 }" @click="changenav2">提现记录</view>
    </view>
    <!-- 收支明细列表 -->
    <view class="leftlist" v-if="index == 1">
      <view class="leftitem" v-for="item in data.list" :key="item.id">
        <view>
          <view style="font-size: 28rpx; font-family: PingFang SC, PingFang SC; font-weight: bold; color: #333333">{{ item.memo }}</view>
          <view style="font-size: 26rpx; font-family: PingFang SC, PingFang SC; font-weight: 500; color: #999999; margin-top: 12rpx">{{ item.createtime }}</view>
        </view>
        <view :class="{ colorstatus: true }" style="font-size: 36rpx; font-family: PingFang SC, PingFang SC; font-weight: bold">
          {{ (item.type == 1 ? '+' : '-') + '￥' + item.money }}
        </view>
      </view>
    </view>
    <!-- 提现记录 -->
    <view class="leftlist" v-if="index == 2">
      <view class="leftitem" v-for="item in data.list" :key="item.id">
        <view>
          <view style="font-size: 28rpx; font-family: PingFang SC, PingFang SC; font-weight: bold; color: #333333">{{ item.memo }}</view>
          <view style="font-size: 26rpx; font-family: PingFang SC, PingFang SC; font-weight: 500; color: #999999; margin-top: 12rpx">{{ item.createtime }}</view>
        </view>
        <view :class="{ colorstatus: false }" style="font-size: 36rpx; font-family: PingFang SC, PingFang SC; font-weight: bold">
          {{ (item.type == 1 ? '+' : '-') + '￥' + item.money }}
        </view>
      </view>
    </view>
  </view>
</template>

<script>
import dayjs from 'dayjs';
export default {
  data() {
    return {
      index: 1,
      data: {}
    };
  },
  methods: {
    changenav1() {
      this.data = {};
      this.index = 1;
      this.getdata();
    },
    changenav2() {
      this.data = {};
      this.index = 2;
      this.getdata();
    },
    // 获取钱包的数据
    async getdata() {
      const res = await uni.$http.post('/teacher/moneyTeacher', {
        type: this.index
      });
      console.log('获取钱包的数据', res);
      this.data = res.data.data;
      this.data.list.forEach((item) => {
        item.createtime = dayjs(item.createtime * 1000).format('YYYY-MM-DD hh:mm:ss');
      });
    },
    // 跳转到提现页面
    tixian() {
      uni.navigateTo({
        url: '/teacher/tixian/tixian?money=' + this.data.okay_money
      });
    }
  },
  onLoad() {
    this.getdata();
  },
  onShow() {
    this.getdata();
  }
};
</script>

<style lang="scss" scoped>
page {
  background-color: #f9f9f9;
}
.container {
  box-sizing: border-box;
  .bgc {
    width: 712rpx;
    height: 302rpx;
    margin: 30rpx 20rpx;
  }
  .money {
    box-sizing: border-box;
    position: absolute;
    display: flex;
    align-items: center;
    width: 712rpx;
    margin-left: 20rpx;
    padding: 0 40rpx 0 50rpx;
    justify-content: space-between;
    color: #ffffff;
    top: 120rpx;
    left: 0rpx;
    .tixian {
      box-sizing: border-box;
      width: 140rpx;
      height: 72rpx;
      text-align: center;
      line-height: 72rpx;
      background: #2142e5;
      border-radius: 100rpx 100rpx 100rpx 100rpx;
    }
  }
  .navbarbox {
    display: flex;
    align-items: center;
    justify-content: space-evenly;
    font-size: 28rpx;
    font-family: PingFang SC, PingFang SC;
    font-weight: 500;
    color: #333333;
  }
  .common {
    font-size: 30rpx;
    font-family: PingFang SC, PingFang SC;
    font-weight: bold;
    color: #3553e8;
    padding-bottom: 6rpx;
    border-bottom: 8rpx solid #3553e8;
  }
  .leftitem {
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 710rpx;
    height: 132rpx;
    margin: 20rpx;
    padding: 22rpx 30rpx;
    background: #ffffff;
    border-radius: 20rpx 20rpx 20rpx 20rpx;
  }
  .colorstatus {
    color: #3553e8;
  }
}
</style>
